// 假设使用一个简单的内存数组来存储路线数据
let routes = [
  {
    id: 1,
    name: "周家庄一日游",
    description: "经典的周家庄一日游路线，涵盖最受欢迎的景点。",
    category: "一日游",
    estimated_time: "5小时",
    rating: 4.8,
    spots: [
      {
        id: 1,
        name: "周家庄农家乐",
        location: "河北省石家庄市...",
        image: "https://example.com/image.jpg"
      }
    ]
  }
];

// 获取推荐路线列表
exports.getRecommendations = (category, keyword) => {
  let filteredRoutes = routes;
  if (category) {
    filteredRoutes = filteredRoutes.filter(route => route.category === category);
  }
  if (keyword) {
    filteredRoutes = filteredRoutes.filter(route =>
      route.name.includes(keyword) ||
      route.spots.some(spot => spot.name.includes(keyword))
    );
  }
  return {
    total: filteredRoutes.length,
    page: 1,
    list: filteredRoutes
  };
};

// 获取路线详情
exports.getRouteById = (id) => {
  return routes.find(route => route.id === parseInt(id));
};

// 创建自定义旅游路线
exports.createRoute = (routeData) => {
  const newRoute = {
    id: routes.length + 1,
    ...routeData
  };
  routes.push(newRoute);
  return newRoute;
};

// 更新旅游路线
exports.updateRoute = (id, updateData) => {
  const routeIndex = routes.findIndex(route => route.id === parseInt(id));
  if (routeIndex !== -1) {
    routes[routeIndex] = { ...routes[routeIndex], ...updateData };
  }
};

// 删除旅游路线
exports.deleteRoute = (id) => {
  routes = routes.filter(route => route.id !== parseInt(id));
};

// 用户自定义路线排序
exports.sortRouteSpots = (route_id, spots_order) => {
  const route = routes.find(route => route.id === parseInt(route_id));
  if (route) {
    route.spots.sort((a, b) => spots_order.indexOf(a.id) - spots_order.indexOf(b.id));
  }
};